//
//  GJMapService.m
//  xmgjAppFront
//
//  Created by Zeki on 2020/7/10.
//  Copyright © 2020 guojutech. All rights reserved.
//

#import "GJMapService.h"
#import "GJOilClassificationModel.h"
#import "GJPetrolStationModel.h"
#import "GJAnnotation.h"
@implementation GJMapService
+(instancetype)shareInstance{
  static GJMapService *instance = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    instance = [GJMapService new];
  });
  return instance;
}


- (void)queryOilClassification:(Complete)commplete{
  [[GJNetWork sharedInstance] getWithURL:GJOilClassification params:@{} success:^(GJResponse * _Nonnull response) {
    if (response.isSuccess) {
      NSArray *data = response.data;
      NSMutableArray *temp = [NSMutableArray new];
      [data eachWithIndex:^(NSDictionary *object, NSUInteger index) {
        GJOilClassificationModel *model = [GJOilClassificationModel mj_objectWithKeyValues:object];
        [temp addObject:model];
      }];
      commplete([GJResult instanceWithSuccess:YES message:@"查询成功" successData:temp]);
    }else{
      commplete([GJResult instanceWithMessage:response.msg]);
    }
  } failure:^(NSString * _Nonnull errorMessage) {
    commplete([GJResult instanceWithMessage:errorMessage]);
  }];
}
- (void)queryNearestPetrolStationWith:(CLLocationCoordinate2D)coordinate commplete:(Complete)commplete{
  [[GJNetWork sharedInstance] postWithURL:GJNearestPetrolStation params:@{@"longitude":@(coordinate.longitude),@"latitude":@(coordinate.latitude)} success:^(GJResponse * _Nonnull response) {
    if (response.isSuccess) {
      GJPetrolStationModel *model = [GJPetrolStationModel mj_objectWithKeyValues:response.data];
      commplete([GJResult instanceWithSuccess:NO message:response.msg successData:model]);
    }else{
      commplete([GJResult instanceWithSuccess:NO message:response.msg successData:nil]);
    }
  } failure:^(NSString * _Nonnull errorMessage) {
    commplete([GJResult instanceWithMessage:errorMessage]);
  }];
}

- (void)queryArroundPetrolStationListWith:(CLLocationCoordinate2D)coordinate distance:(NSString *)distance businessNo:(NSString *)businessNo commplete:(Complete)commplete{
  [[GJNetWork sharedInstance] getWithURL:GJArroundPetrolStation params:@{
    @"longitude":@(coordinate.longitude),
    @"latitude":@(coordinate.latitude),
    @"distance":@(999999),
    @"businessNo":businessNo
  } success:^(GJResponse * _Nonnull response) {
    if (response.isSuccess) {
      NSArray *data = response.data;
      NSMutableArray *temp = [NSMutableArray array];
      [data eachWithIndex:^(id object, NSUInteger index) {
        GJPetrolStationModel *model = [GJPetrolStationModel mj_objectWithKeyValues:object];
        GJAnnotation *annotation = [GJAnnotation new];
        annotation.model = model;
        if (index == 0) {
          annotation.isNearest = YES;
        }else{
          annotation.isNearest = NO;
        }
        [temp addObject:annotation];
      }];
      commplete([GJResult instanceWithSuccess:NO message:response.msg successData:temp]);
    }else{
      commplete([GJResult instanceWithSuccess:NO message:response.msg successData:nil]);
    }
  } failure:^(NSString * _Nonnull errorMessage) {
    commplete([GJResult instanceWithMessage:errorMessage]);
  }];
}
@end
